﻿namespace Sidvall.AuthorizationManager.UI.Entities
{
	public partial class FilterContext
	{
		#region GetItem

		public static FilterContext GetItem(Sidvall.AuthorizationManager.Net.Services.V1.FilterContext dataItem)
		{
			FilterContext item;

			if (dataItem == null)
				return null;
			item = new FilterContext();
			item.Import(dataItem, Sidvall.Data.CopySettings.FullCopyAll(Sidvall.Data.DataRowContextOption.None, null));

			return item;
		}

		#endregion

		#region Deserialize

		public static FilterContext Deserialize(string value)
		{
			Sidvall.AuthorizationManager.Net.Services.V1.FilterContext dataItem;
			FilterContext item;

			try
			{
				dataItem = Sidvall.Serialization.SerializerManager.Current.Deserialize<Sidvall.AuthorizationManager.Net.Services.V1.FilterContext>(value);
			}
			catch
			{
				dataItem = null;
			}
			if (dataItem == null)
				dataItem = new Net.Services.V1.FilterContext();
			item = GetItem(dataItem);
			item.AcceptChanges();

			return item;
		}

		#endregion
		#region Serialize

		public string Serialize()
		{
			return Serialize(this);
		}
		public static string Serialize(FilterContext item)
		{
			Sidvall.AuthorizationManager.Net.Services.V1.FilterContext dataItem;

			dataItem = new Net.Services.V1.FilterContext();
			dataItem.Import(item, Sidvall.Data.CopySettings.FullCopyAll(Sidvall.Data.DataRowContextOption.None, null));

			return Sidvall.Serialization.SerializerManager.Current.SerializeObject(dataItem);
		}

		#endregion
	}
}